
<?php
	session_start(); // On démarre la session AVANT toute chose
?>
<!DOCTYPE html>
	<html>
		<head>

			<meta charset="utf-8" />
			<link rel="stylesheet" href="style.css" />
			<title>Rechercher un livre</title>
		</head>
	 
		<body>
			<header>
				<table>
					<tr>
						<td>			
							<div id="titre_principal">
								<a href="index.php">
									<img src="livre.jpg" alt="Logo AEO" id="logo" />
								</a>
								<h1>AEO<br />Bibliothèque</h1>
							</div>			
						</td>
					</tr>
				</table>
			</header>
			<hr/>

			<div id="contenu_site">
				<h6><a href="index.php">Index</a> > Rechercher</h6>
				<?php 
					if ($_GET['action']=='Ask' && $_SESSION['acces']=='ok')
					{
						echo "Que voulez-vous faire?";?>
						<form action="#" method="post">
							<input type="radio" name="choix" value="emprunter" id="emprunter" checked="checked" /><Label for="emprunter">Emprunter le livre</Label> 
							<input type="radio" name="choix" value="rendre" id="rendre" /><Label for="rendre">Rendre le livre</Label>
							<input type="radio" name="choix" value="reserver" id="reserver" /><Label for="reserver">Réserver le livre</Label>
							<input type="submit" value="Valider" />
						</form>
						<?php
							if(isset($_POST['choix']))
							{
								//echo "coucou";
								if($_POST['choix']=='rendre')
								{
									header('Location: rendre.php?ref=\''.$_GET['ref']. '\'');
								}
								elseif($_POST['choix']=='emprunter')
								{
									header('Location: emprunter.php?ref=\''.$_GET['ref']. '\'');
								}
								elseif($_POST['choix']=='reserver')
								{
									header('Location: reserver.php?ref=\''.$_GET['ref']. '\'');
								}
							}
					}
					elseif($_SESSION['acces']!='ok')
					{?>
						
				
						<p>Veuillez vous enregistrer</p>
						<form action="#" method="post">
							<p>
							<input type="text" name="id" />
							<input type="password" name="mdp" />
							<input type="submit" value="Valider" />
							</p>
						</form>
						<?php
							if(isset($_POST['id']) AND isset($_POST['mdp']))
							{
								//var_dump($_POST['Valider']);
								if($_POST['id']=='user' AND $_POST['mdp']='aeobib')
								{
									$_SESSION['acces']='ok';
									if($_GET['action']=='Rendre')
									{
										header('Location: rendre.php');
									}
									elseif($_GET['action']=='Emprunter')
									{
										header('Location: emprunter.php?ref=\''.$_GET['ref']. '\'');
									}
									elseif($_GET['action']=='Reserver')
									{
										header('Location: reserver.php');
									}
									else
									{
										header('location : protection.php?action=Ask');
									}
								}
								else 
								{
									echo "Identifiants incorects";
									header('Refresh: 3;URL=protection.php?action='.$_GET['action']);
								}
							}
					}
					elseif($_GET['action']!='Ask' && $_SESSION['acces']=='ok')
					{	
						if($_GET['action']=='Rendre')
						{
							header('Location: rendre.php');
						}
						elseif($_GET['action']=='Emprunter')
						{
							header('Location: emprunter.php');
						}
						elseif($_GET['action']=='Reserver')
						{
							header('Location: reserver.php');
						}
					}
								
				?>
			</div>
			
			<hr/>
			<footer>
				<table>
					<tr>
						<td>			
							<div id="titre_footer">
								<h5>AEO Bibliothèque ~ Projet ISN 2012-2013<br />ANDRES Guillaume, ECKEL Patrick, OUADIR Guillaume</h5>
							</div>			
						</td>
					</tr>
				</table>
			</footer>
		</body>
</html>